<template>
    <!--线索详情页面-->
    <div>
        <div style="border:1px solid #BFBFBF;padding: 10px;background-color: white;height: 140px">
            <el-form v-model="cluelist" :label-position="labelPosition" >
                <div>
                    <el-row :gutter="20" style="height:41px">
                        <el-col :span="6" >
                            <el-form-item>
                                <i class="el-icon-s-custom" style="margin-left: 10px; font-size: 19px;"></i>
                                <span style="font-weight: bold;font-size: 18px;margin-left: 10px">{{cluelist.clueName}}</span>
                                <span style="display: none">id:{{cluelist.clueId}}</span>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6" :offset="12">
                            <el-form-item>
                                <el-button class="el-icon-user-solid" style="margin-left: 10px;"
                                           @click="zhuanclent(cluelist)">转客户</el-button>
                                <el-button class="el-icon-edit"
                                           @click="xgclient(cluelist.clueId)">编辑</el-button>
                                <el-button class="el-icon-back" @click="gotoMenufh">返回</el-button>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </div>
                <!--下-->
                <div style="border-top: 1px solid #DDDDDD;margin-top: 10px">
                    <div style="height: 150px;margin-left: 10px;">
                        <el-row type="flex" :gutter="20" style="margin-top: 20px">
                            <el-col :span="2">
                                <span style="color: gray">线索来源：</span>
                            </el-col>
                            <el-col :span="10">
                                <span style="color: black">{{cluelist.clueSource}}</span>
                            </el-col>
                            <el-col :span="2">
                                <span style="color: gray">手机：</span>
                            </el-col>
                            <el-col :span="4">
                                <span style="color: black">{{cluelist.clueLinkmansj}}</span>
                            </el-col>
                        </el-row>
                        <el-row type="flex" :gutter="20" style="margin-top: 15px">
                            <el-col :span="2">
                                <span style="color: gray">负责人：</span>
                            </el-col>
                            <el-col :span="10">
                                <span style="color: black">{{cluelist.empId.empName}}</span>
                            </el-col>
                            <el-col :span="2">
                                <span style="color: gray">更新时间：</span>
                            </el-col>
                            <el-col :span="4">
                                <span style="color: black">{{cluelist.clueUptime | formatDate}}</span>
                            </el-col>
                        </el-row>
                        <el-row type="flex" :gutter="20" style="margin-top: 15px">
                        </el-row>
                    </div>
                </div>
            </el-form>
        </div>
        <!--进度详情-->
        <div style="margin-top: 5px;border: 1px solid #BFBFBF;background-color: white;">
            <div>
                <template>
                    <el-tabs v-model="activeName2" type="card">
                        <el-tab-pane label="基本信息" name="first" style="height: 410px;">
                            <div class="shugan" style="margin-left: 20px;"></div>
                            <span style="margin-left: 10px;font-size: 14px;">基本信息</span>
                            <el-form v-model="cluelist" style="margin-left: 20px;" :label-position="labelPosition" >
                                <div>
                                    <div style="height: 150px;margin-left: 10px;">
                                        <el-row type="flex" :gutter="20" style="margin-top: 20px">
                                            <el-col :span="3">
                                                <span style="color: gray">线索名称：</span>
                                            </el-col>
                                            <el-col :span="10">
                                                <span style="color: black">{{cluelist.clueName}}</span>
                                            </el-col>
                                            <el-col :span="3">
                                                <span style="color: gray">线索来源：</span>
                                            </el-col>
                                            <el-col :span="4">
                                                <span style="color: black">{{cluelist.clueSource}}</span>
                                            </el-col>
                                        </el-row>
                                        <el-row type="flex" :gutter="20" style="margin-top: 15px">
                                            <el-col :span="3">
                                                <span style="color: gray">电话：</span>
                                            </el-col>
                                            <el-col :span="10">
                                                <span style="color: black">{{cluelist.cluePhone}}</span>
                                            </el-col>
                                            <el-col :span="3">
                                                <span style="color: gray">联系人：</span>
                                            </el-col>
                                            <el-col :span="4">
                                                <span style="color: black">{{cluelist.clueLinkmanname}}</span>
                                            </el-col>
                                        </el-row>
                                        <el-row type="flex" :gutter="20" style="margin-top: 20px">
                                            <el-col :span="3">
                                                <span style="color: gray">地址：</span>
                                            </el-col>
                                            <el-col :span="10">
                                                <span style="color: black">{{cluelist.clueSite}}</span>
                                            </el-col>
                                            <el-col :span="3">
                                                <span style="color: gray">手机：</span>
                                            </el-col>
                                            <el-col :span="4">
                                                <span style="color: black">{{cluelist.clueLinkmansj}}</span>
                                            </el-col>
                                        </el-row>
                                        <el-row type="flex" :gutter="20" style="margin-top: 20px">
                                            <el-col :span="3">
                                                <span style="color: gray">备注：</span>
                                            </el-col>
                                            <el-col :span="10">
                                                <span style="color: black">{{cluelist.clueRemark}}</span>
                                            </el-col>
                                            <el-col :span="3">
                                                <span style="color: gray">下次联系时间：</span>
                                            </el-col>
                                            <el-col :span="4">
                                                <span style="color: black">{{cluelist.clueEstablishtime | formatDate}}</span>
                                            </el-col>
                                        </el-row>
                                        <el-row type="flex" :gutter="20" style="margin-top: 15px">
                                        </el-row>
                                    </div>
                                </div>
                            </el-form>
                        </el-tab-pane>
                        <el-tab-pane label="附件" name="eight" style="height: 410px;">
                            <div>
                                <!--附件信息-->
                                <template>
                                    <el-table border style="width: 900px; margin: 0 auto;" height="350">
                                        <el-table-column fixed prop="date" label="附件名称" width="200">
                                        </el-table-column>
                                        <el-table-column prop="name" label="附件大小" width="100">
                                        </el-table-column>
                                        <el-table-column prop="province" label="上传人" width="200">
                                        </el-table-column>
                                        <el-table-column prop="province" label="上传时间" width="200">
                                        </el-table-column>
                                        <el-table-column prop="province" label="操作" width="200">
                                        </el-table-column>
                                    </el-table>
                                </template>
                            </div>
                        </el-tab-pane>
                        <el-tab-pane label="操作记录" name="nine" style="height: 410px;">
                            <div class="block">
                                <div class="radio" style="margin-left: 38px;">
                                    <el-radio-group v-model="reverse">
                                        <el-radio :label="true">倒序</el-radio>
                                        <el-radio :label="false">正序</el-radio>
                                    </el-radio-group>
                                </div>

                                <el-timeline :reverse="reverse" style="margin-top: 40px;">
                                    <el-timeline-item v-for="(item) in activities"
                                                      :key="item.operationId" :timestamp="item.operationTime | formatDate">
                                        <el-col :span="3">
                                            操作人:
                                            <span style="color: #409EFF;margin-right: 30px;">{{item.empId.empName}}</span>
                                        </el-col>
                                        <el-col :span="3">
                                            {{item.operationContent}}
                                        </el-col>
                                        <el-col :span="2">
                                            <i class="el-icon-s-custom" style="margin-left: 15px; font-size: 15px;"></i>
                                            <span style="color: #409EFF;margin-left: 10px;">{{item.clueId.clueName}}</span>
                                        </el-col>
                                    </el-timeline-item>
                                </el-timeline>
                            </div>
                        </el-tab-pane>
                    </el-tabs>
                </template>
            </div>
        </div>
    </div>
</template>

<script>
    import {formatTimeToStr} from '../router//format.js';
    import Crypto  from '../router//secret.js'
    export default {
        name: "TfyClientParticularsPage",
        data() {
            return {
                /*对齐方式*/
                labelPosition:'left',
                /*保存传过来的row*/
                cluelist:{
                    clueId:0,
                    empId:{//员工表
                        empId:0,
                        empName:'',
                        depId:{//部门
                            depId:0,
                            depName:'',
                        },
                    },
                    clueEstablishtime:'',
                    clueName:'',
                    clueSource:'',
                    cluePhone:'',
                    clueMobile:'',
                    clueRemark:'',
                    cluePeople:'',
                    clueSite:'',
                    clueUptime:'',
                    clueLinkmanname:'',
                    clueLinkmansj:'',
                    clueSz:'',
                    operationId:{
                        operationId:0,
                        operationContent:'',
                        operationTime:'',
                    }
                },
                bjjilutankuan:false,
                options: [{
                    value: '选项1',
                    label: '我负责的线索'
                }, {
                    value: '选项2',
                    label: '属下负责的线索'
                }, {
                    value: '选项3',
                    label: '已转化的线索'
                }, {
                    value: '选项4',
                    label: '全部线索'
                }],
                value: '',
                //快捷日期选择器
                pickerOptions: {
                    disabledDate(time) {
                        return time.getTime() > Date.now();
                    },
                    shortcuts: [{
                        text: '今天',
                        onClick(picker) {
                            picker.$emit('pick', new Date());
                        }
                    }, {
                        text: '昨天',
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24);
                            picker.$emit('pick', date);
                        }
                    }, {
                        text: '一周前',
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', date);
                        }
                    }]
                },
                /*是否显示记录值div*/
                jl:false,
                activeName2: 'first',
                //操作记录-时间线
                reverse: true,
                activities: [],
            };
        },
        methods: {
            zhuanclent(cluelist){
                window.console.log("1212"+cluelist)
                var list = JSON.stringify({xs:cluelist});
                this.$confirm('此操作将线索转为客户, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$axios.post("http://localhost:8088/pinkclient-list",this.qs.stringify({
                        xs:list
                    })).then(v=> {
                        this.$message({
                            showClose: true,
                            type: 'success',
                            message: '转客户成功!',
                        });
                        this.$router.push({//跳kh页面
                            path:'/tfykh',
                            query: {
                                row:v.data,
                            }
                        })
                    }).catch(v=> {
                        alert("加载失败转客户："+v.data);
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消转客户'
                    });
                });
            },
            xgclient(clueId){//客户修改方法
                clueId = escape(Crypto.set(clueId));//加密数据
                this.$router.push({
                    path:'/xjxs',
                    query: {
                        clueId:clueId
                    }
                });
            },
            //线索查询
            initData(){
                var clueId = Crypto.get(unescape(this.$route.query.row));
                this.$axios.get("http://localhost:8088/selectxsid-list",
                    {params:{clueId:clueId}}).then(v=>{
                        this.cluelist = v.data;
                        this.bjxxcx(parseInt(clueId));
                        this.czlist(parseInt(clueId));//操作
                }).catch();
            },
            //根据线索id查询操作记录
            czlist(clueId){
                this.$axios.post("http://localhost:8088/findAllxscz-list",this.qs.stringify(
                    {clueId:parseInt(clueId)})).then(v=>{
                    this.activities = v.data;
                }).catch();
            },
            bjxxcx(clueId){
                this.$axios.post("http://localhost:8088/selectxsid-list",this.qs.stringify(
                    {clueId:parseInt(clueId)})).then(v=>{
                    this.cluelist = v.data;
                }).catch();
            },
            gotoMenu(){
                this.$router.replace('/xjxs')
            },
            gotoMenufh(){
                this.$router.replace('/tfyxs')
            },
            showjl(){
                this.jl=true;
            },
        },
        created: function () {//查询从列表页面传值初始化方法
            if(this.$route.query.row != null){
                this.initData();
            }
        },
        filters:{//日期格式化
            formatDate: function(time) {
                if(time != null && time != ""){
                    var date = new Date(time);
                    return formatTimeToStr(date, "yyyy-MM-dd hh:mm:ss");
                }else{
                    return "";
                }
            }
        }
    }
</script>

<style scoped>
    .shugan{
        border-left-color: rgb(70, 205, 207);
        border-left-width: 4.8px;
        height: 10px;
        border-left-style: solid;
        display: inline;
        font-size: 13px;
    }
</style>